package com.justech.eat.service.impl;

import com.justech.common.vo.PageDto;
import com.justech.eat.controller.req.OrderDefaultSetReq;
import com.justech.eat.controller.req.OrderDetailReq;
import com.justech.eat.entity.Order;
import com.justech.eat.entity.OrderDefaultSet;
import com.justech.eat.entity.OrderDetail;
import com.justech.eat.entity.OrderDetailAbnormalRecord;
import com.justech.eat.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: eat-service
 * @description:
 * @author: feifei.li
 * @create: 2020-06-13 19:29
 **/
@Service
public class OrderApplicationServiceImpl implements OrderApplicationService {

    @Autowired
    OrderService orderService;
    @Autowired
    OrderDetailService orderDetailService;
    @Autowired
    OrderDefaultSetService orderDefaultSetService;
    @Autowired
    OrderBatchService orderBatchService;
    @Autowired
    UserOrientedOrderService userOrientedOrderService;

    @Override
    public List<Order> getByDate(String date) {
        return orderBatchService.getByDate(date);
    }

    @Override
    public List<Order> add(List<Order> orders) {
        return orderBatchService.add(orders);
    }

    /**
     * 获取用户的默认报餐设置
     *
     * @param jobNumber 不可以为空
     * @return
     */
    @Override
    public OrderDefaultSet getByJobNumber(String jobNumber) {
        return orderDefaultSetService.getByJobNumber(jobNumber);
    }

    /**
     * 设置默认报餐
     *
     * @param jobNumber 不可为空
     * @param lunch     1表示报，0表示不报 不可为空
     * @param dinner    1表示报，0表示不报 不可为空
     * @param meal      1表示报，0表示不报 不可为空
     * @param night     1表示报，0表示不报 不可为空
     * @return 保存成功后返回最新的设置详情
     */
    @Override
    public OrderDefaultSet set(String jobNumber, int lunch, int dinner, int meal, int night) {
        return orderDefaultSetService.set(jobNumber, lunch, dinner, meal, night);
    }

    @Override
    public void add(OrderDetail orderDetail) {
        orderDetailService.add(orderDetail);
    }

    @Override
    public void delete(int id) {
        orderDetailService.delete(id);
    }

    @Override
    public void update(int id, long orderId, int type, int result, boolean isFinal) {
        orderDetailService.update(id, orderId, type, result, isFinal);
    }

    @Override
    public OrderDetail queryById(int id) {
        return orderDetailService.queryById(id);
    }

    /**
     * 受理订单明细更改
     *
     * @param id
     * @param result
     * @return
     */
    @Override
    public OrderDetail update(int id, int result) {
        return orderDetailService.update(id, result);
    }

    /**
     * 修改对象
     *
     * @param orderDetail
     * @return
     */
    @Override
    public OrderDetail update(OrderDetail orderDetail) {
        return orderDetailService.update(orderDetail);
    }

    /**
     * 查询用户订餐记录
     *
     * @param date
     * @param jobNumber
     * @param type
     * @return
     */
    @Override
    public OrderDetail getOrderDetail(String date, String jobNumber, int type) {
        return orderDetailService.getOrderDetail(date, jobNumber, type);
    }

    /**
     * 处理异常结果
     *
     * @param date
     * @param jobNumber
     * @param type
     * @param result
     * @return 该方法的返回的数据不靠谱，请慎重使用
     */
    @Override
    public OrderDetail processAbnormal(String date, String jobNumber, int type, int result) {
        return orderDetailService.processAbnormal(date, jobNumber, type, result);
    }

    /**
     * 处理将要订版的记录
     *
     * @param date
     * @param jobNumber
     * @param type
     * @return
     */
    @Override
    public OrderDetail finalOrderDetail(String date, String jobNumber, int type) {
        return orderDetailService.finalOrderDetail(date, jobNumber, type);
    }

    @Override
    public void add(Order order) {
        orderService.add(order);
    }

    @Override
    public void delete(long id) {
        orderService.delete(id);
    }

    @Override
    public void update(long id, String deviceInfo) {
        orderService.update(id, deviceInfo);
    }

    @Override
    public Order queryById(long id) {
        return orderService.queryById(id);
    }

    /**
     * 查询员工当前月的报餐明细
     *
     * @param jobNumber
     * @return
     */
    @Override
    public List<Order> thisMonthOrders(String jobNumber) {
        return userOrientedOrderService.thisMonthOrders(jobNumber);
    }

    /**
     * 查询用户上个月的报餐明细
     *
     * @param jobNumber
     * @return
     */
    @Override
    public List<Order> previousMonthOrders(String jobNumber) {
        return userOrientedOrderService.previousMonthOrders(jobNumber);
    }

    /**
     * 获取某个用户区间内的报餐明细
     *
     * @param s         开始日期
     * @param e         结束日期
     * @param jobNumber 用户工号
     * @return
     */
    @Override
    public List<Order> getMonthOrders(String s, String e, String jobNumber) {
        return userOrientedOrderService.getMonthOrders(s, e, jobNumber);
    }

    /**
     * 提交一日报餐信息
     *
     * @param orderDetailReq
     * @param date
     * @param jobNumber
     * @return
     */
    @Override
    public List<Order> book(OrderDetailReq orderDetailReq, String date, String jobNumber) {
        return userOrientedOrderService.book(orderDetailReq, date, jobNumber);
    }

    /**
     * 设置默认报餐信息
     *
     * @param orderDefaultSetReq
     * @param jobNumber
     * @return
     */
    @Override
    public OrderDefaultSet defaultSet(OrderDefaultSetReq orderDefaultSetReq, String jobNumber) {
        return userOrientedOrderService.defaultSet(orderDefaultSetReq, jobNumber);
    }

    /**
     * 查询用户的异常信息
     *
     * @param jobNumber
     * @param page
     * @param size
     * @return
     */
    @Override
    public PageDto<OrderDetailAbnormalRecord> getAbnormalRecord(String jobNumber, Integer page, Integer size) {
        return userOrientedOrderService.getAbnormalRecord(jobNumber, page, size);
    }

    /**
     * 查询用户的异常信息
     *
     * @param jobNumber
     * @param date
     * @param page
     * @param size
     * @return
     */
    @Override
    public PageDto<OrderDetailAbnormalRecord> getAbnormalRecordByDate(String jobNumber, String date, Integer page, Integer size) {
        return userOrientedOrderService.getAbnormalRecordByDate(jobNumber, date, page, size);
    }
}
